$(function() {
	//文本搜索
	$("#searchSubmit").click(function () {
		var searchText = $("#searchContent").val();
		window.location.href = "product.html?text=" + searchText;
	});
	//商标详情
	$(".trademark").click(function (){
		var tid = $(this).attr("data-id");
		$.ajax({
			type:"get",	//提交方式
			url:'/trademarks/getdetail.html',
			data:{tid:tid},
			dataType: "json",
			success:function (res) {
				var id = res.data.id;
				if (id == undefined || id == 'undefined' || id == null || id == "null" || id == "NULL") {
					alert("商标已下架");
					window.location.reload();
					return;
				}
				var lei  = res.data.lei;
				var name = res.data.name;
				var price = res.data.price;
				var brother = res.data.brother;
				var leiname = res.data.lei_name;
				var colorimg = res.data.thumb_image;
				var originimg = res.data.trademark_image;
				var brotherCount = res.data.brotherCount;
				var brotherMd = ( typeof res.data.md != 'undefined' ) ? res.data.md : "";
				var goodsTeam = ( typeof res.data.team != 'undefined' ) ? res.data.team : "";
				var sqName = ( typeof res.data.sqName != 'undefined' ) ? res.data.sqName : "";
				var goodsService = ( typeof res.data.goods != 'undefined' ) ? res.data.goods : "";
				var sqAddress = ( typeof res.data.sqAddress != 'undefined' ) ? res.data.sqAddress : "";
				var registeredDate = ( typeof res.data.registeredDate != 'undefined' ) ? res.data.registeredDate : "";
				var concatUserMobile = ( typeof res.data.concat.mobile != 'undefined' ) ? res.data.concat.mobile : "";
				var concatUserName = ( typeof res.data.concat.user_name != 'undefined' ) ? res.data.concat.user_name : "";
				var concatUserQrcodeUrl = ( typeof res.data.concat.qrcode_url != 'undefined' ) ? res.data.concat.qrcode_url : "";
				$("#myModal .modal_title h2").text( name + "-" + lei + "类" );
				$("#myModal #picts").attr("src",colorimg);
				$("#myModal #picts").attr("color-img",colorimg);
				$("#myModal #picts").attr("origin-img",originimg);
				$("#myModal .trademarkbox-baseinfo .goods_title").text(name);
				$("#myModal .trademarkbox-baseinfo .price").text(price + "元");
				$("#myModal .trademarkbox-baseinfo .goods_brother").text("共"+brotherCount+"类");
				$("#myModal .trademarkbox-baseinfo .goods_brother").css({"color":"rgba(38, 38, 38, 1)"});
				if( brother != "" ){
					$("#myModal .trademarkbox-baseinfo .goods_brother").text("共"+brotherCount+"类("+brother+")");
					if(brotherMd != ""){
						$("#myModal .trademarkbox-baseinfo .goods_brother").css({"color":"#587aea"});
						$("#myModal .trademarkbox-baseinfo .goods_brother").attr("data-md",brotherMd);
					}
				}
				$("#myModal .trademarkbox-baseinfo .goods_lei").text(lei + "(" + leiname + ")");
				if( id != "" ){
					$("#myModal .trademarkbox-baseinfo .goods_id .goods_id_detail").text(id);
					$("#myModal .trademarkbox-baseinfo .goods_id").show();
				}
				if( registeredDate != "" ){
					$("#myModal .trademarkbox-baseinfo .goods_registered .goods_registered_date").text(registeredDate);
					$("#myModal .trademarkbox-baseinfo .goods_registered").show();
				}
				if( goodsTeam != "" ){
					$("#myModal .trademarkbox-baseinfo .goods_team .goods_team_detail").text(goodsTeam);
					$("#myModal .trademarkbox-baseinfo .goods_team").show();
				}
				if( goodsService != "" ){
					$("#myModal .trademarkbox-baseinfo .goods_service .goods_service_detail").text(goodsService);
					$("#myModal .trademarkbox-baseinfo .goods_service").show();
				}
				if(sqName != "") {
					$("#myModal .trademarkbox-baseinfo .goods_apply .goods_apply_name").text(sqName);
					$("#myModal .trademarkbox-baseinfo .goods_apply").show();
				}
				if(sqAddress != "") {
					$("#myModal .trademarkbox-baseinfo .goods_address .goods_addres_detail").text(sqAddress);
					$("#myModal .trademarkbox-baseinfo .goods_address").show();
				}
				//商标联系人
				if( concatUserMobile !="" || concatUserName != "" || concatUserQrcodeUrl != "" ){
					if( concatUserName != "" ){
						$("#myModal .contact .concat_user_name").text(concatUserName);
					}
					if( concatUserMobile != "" ){
						$("#myModal .contact .concat_user_mobile").text(concatUserMobile);
						$("#myModal .contact .concat_user_mobile").attr("href","tel:" + concatUserMobile);
					}
					if( concatUserQrcodeUrl != "" ){
						$("#myModal .contact .code img").attr("src",concatUserQrcodeUrl);
					}
					$("#myModal .contact").show();
				}
				$("#myModal").show();
			},
		});
	});
	//商标详情关闭
	$("#myModal .close").click(function (){
		$("#myModal").hide();
		$("#myModal .trademarkbox-baseinfo .goods_id").hide();
		$("#myModal .trademarkbox-baseinfo .goods_registered").hide();
		$("#myModal .trademarkbox-baseinfo .goods_team").hide();
		$("#myModal .trademarkbox-baseinfo .goods_service").hide();
		$("#myModal .trademarkbox-baseinfo .goods_apply").hide();
		$("#myModal .trademarkbox-baseinfo .goods_address").hide();
		$("#myModal .contact").hide();
	});
	//商标详情，切换图片
	$("#myModal #change_pic").click(function (){
		var curimg = $("#myModal #picts").attr("src");
		var colorimg = $("#myModal #picts").attr("color-img");
		var originimg = $("#myModal #picts").attr("origin-img");
		if( curimg == colorimg ){
			$("#myModal #picts").attr("src",originimg);
		}else{
			$("#myModal #picts").attr("src",colorimg);
		}
	});
	//勾选多类
	$("#more-cate").click(function (){
		if( $(this).is(":checked") == false ) {
			//取消勾选刷新当前页面
			window.location.href='product.html';
		}else{
			//全部隐藏
			$(".category_group_box").hide();
			$(".category_group_box .category_group_title").hide();
			//重置用户选择
			$(".category_group_box .group_list .similar").removeClass("bgs");
			$(".category_group_box .group_list_word .word").removeClass("bgs");
		}
	});
	//切换商品，切换群组
	$(".submenu .submenu_content .group .group_r .group_classify .group_title .cut").click(function (){
		if( $("#category_group_type").hasClass("category_good") ){
			$("#category_group_type").text("切换为商品");
			$("#category_group_type_desc").text("按群组选择");
			$("#category_group_type").removeClass("category_good").addClass("category_group");
			$(".category_group_box .group_list_word").hide();
			//重置用户选择
			$(".category_group_box .group_list .similar").removeClass("bgs");
			$(".category_group_box .group_list_word .word").removeClass("bgs");
			//显示区域
			$(".category_group_box .group_list").show();
		}else if( $("#category_group_type").hasClass("category_group") ){
			$("#category_group_type").text("切换为群组");
			$("#category_group_type_desc").text("按产品选择");
			$("#category_group_type").removeClass("category_group").addClass("category_good");
			$(".category_group_box .group_list").hide();
			//重置用户选择
			$(".category_group_box .group_list .similar").removeClass("bgs");
			$(".category_group_box .group_list_word .word").removeClass("bgs");
			//显示区域
			$(".category_group_box .group_list_word").show();
		}
	});
	//分类搜索选择分类
	$('.submenu .submenu_content .group .group_l li').click(function () {
		var cid = $(this).attr("data-id");
		if( $("#more-cate").is(":checked") ) {
			$("#category_group_title_" + cid).show();
		}else {
			$("#category_group_box_" + cid).siblings('.category_group_box').hide();
		}
		//判断当前视图
		if( $("#category_group_type").hasClass("category_good") ) {
			$("#category_group_box_" + cid + " .group_list_word").show();
			$("#category_group_box_" + cid + " .group_list").hide();
		}else if( $("#category_group_type").hasClass("category_group") ) {
			$("#category_group_box_" + cid + " .group_list_word").hide();
			$("#category_group_box_" + cid + " .group_list").show();
		}
		//显示数据区域
		$("#category_group_box_" + cid).show();
		//添加选中样式
		if( $("#more-cate").is(":checked") ) {
			if( !$(this).hasClass('on') ){
				$(this).addClass('on')
			}
		}else{
			$(this).addClass('on').siblings('li').removeClass('on');
		}
	});
	//选择群组
	$(".category_group_box .group_list .similar").click(function (){
		if( $(this).hasClass("bgs") ){
			$(this).removeClass('bgs');
		}else {
			$(this).addClass('bgs');
		}
	});
	//选择商品
	$(".category_group_box .group_list_word .word").click(function (){
		if( $(this).hasClass("bgs") ){
			$(this).removeClass('bgs');
		}else {
			$(this).addClass('bgs');
		}
	});
	//分类搜索关闭分组
	$(".category_group_box .category_group_box_close").click(function (){
		var cid = $(this).attr("data-id");
		$("#category_group_box_" + cid).hide();
		$("#category_group_box_" + cid + " .group_list .similar").removeClass('bgs');
		$("#category_left_menu_" + cid).removeClass('on');
	});
});

/**
 * 联系客服
 */
function kf() {
	$.ajax({
		type:"get",
		url:"/index/getkefu",
		success:function(obj){
			data = $.parseJSON(obj);
			var qrcode = data.data.kefu_qrcode_url;
			var imgHtml = "<img src='"+qrcode+"' style='max-width:60%;max-height:60%;text-align:center; display: block; margin: 20px auto;'/>";
			//弹出层
			layer.open({
				type: 1,
				shade: 0.8,
				offset: 'auto',
				// area: [300 + 'px',300+'px'],  // area: [width + 'px',height+'px']  //原图显示
				shadeClose: true,
				scrollbar: false,
				title: "长按识别二维码添加客服微信", //显示标题
				content: imgHtml, //捕获的元素，注意：最好该指定的元素要存放在body最外层，否则可能被其它的相对元素所影响
				cancel: function() {
					//layer.msg('捕获就是从页面已经存在的元素上，包裹layer的结构', { time: 5000, icon: 6 });
				}
			});
		}
	})
}

/**
 * 获取url参数
 * @param url
 * @returns {{}}
 */
function getUrlParams(url) {
	var params = {};
	url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str, key, value) {
		params[key] = decodeURIComponent(value);
		console.log("key" + key + "=val=" + decodeURIComponent(value))
	});
	return params;
}

/**
 * 判断是否是数字
 * @param input
 * @returns {boolean}
 */
function isNumber(input) {
	var pattern = /^\d+$/; // 只包含数字的正则表达式
	return pattern.test(input);
}